<?php

	// TITLE: Serves_on AUTO MODEL
	// FILE: scaffolding/model/serves_on.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createServesOn = function($con, $servesOn) {
		$sql = 'INSERT INTO serves_on (volunteer_id, committee_id, is_officer) VALUES (';
		$sql .= $serves_on->getVolunteerId() . ', ';
		$sql .= $serves_on->getCommitteeId() . ', ';
		$sql .= $serves_on->getIsOfficer() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readServesOn = function($con, $id) {
		$sql = 'SELECT * FROM serves_on WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$servesOn = new ServesOn();
			$servesOn->setVolunteerId($dbio->select($readVolunteer(result[0])));
			$servesOn->setCommitteeId($dbio->select($readCommittee(result[1])));
			$servesOn->setIsOfficer(result[2]);
		} else {
			$servesOn = false;
		}
		return $servesOn;
	};

	$updateServesOn = function($con, $servesOn) {
		$sql = 'UPDATE serves_on SET ';
		$sql .= 'volunteer_id = ' . $serves_on->getVolunteerId() . ', ';
		$sql .= 'committee_id = ' . $serves_on->getCommitteeId() . ', ';
		$sql .= 'is_officer = ' . $serves_on->getIsOfficer() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteServesOn = function($con, $id) {
		$sql = 'DELETE FROM serves_on WHERE volunteer_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listServesOn = function($con) {
		$sql = 'SELECT * FROM serves_on';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$servesOns = array();
			while ($result = mysqli_fetch_array($results)) {
				$servesOn = new ServesOn();
				$servesOn->setVolunteerId($dbio->select($readVolunteer(result[0])));
				$servesOn->setCommitteeId($dbio->select($readCommittee(result[1])));
				$servesOn->setIsOfficer(result[2]);
				$servesOns[] = servesOn;
			}// end while
		} else {
			$servesOns = false;
		}
		return $servesOns;
	};

